<!DOCTYPE html>
<html lang="zh">
<head>
    <meta charset="UTF-8">
    <title>canvas01</title>
    <style>
        body{
            margin: 0;
            padding: 0;
            background: pink;
        }
        #cc{
            background: gray;
            position: absolute;
            left: 0;
            right: 0;
            bottom: 0;
            top: 0;
            margin: auto;
        }
    
    </style>
</head>
<body>
    <canvas id="cc" width="600" height="600"></canvas>
    <script>
        window.onload=function(){
            // 获取画布元素；
            var cc=document.querySelector("#cc");
            // 判断是否支持画笔
            if(cc.getContext){
                // 定义一个画笔；
                var ctx=cc.getContext("2d");
                var img=new Image();
                img.src="nike.jpg";
                img.onload=function(){
                    draw();
                }
                function draw(){
                   var gradient= ctx.createRadialGradient(300,300,100,300,300,300);
                   gradient.addColorStop(0,"red");
                   gradient.addColorStop(0.3,"green");
                   gradient.addColorStop(0.5,"yellow");
                   ctx.fillStyle=gradient;
                   ctx.fillRect(0,0,600,600);
                //  var pattern=ctx.createPattern(img,"no-repeat");
                    // ctx.fillStyle=pattern;
                    // // ctx.drawImage(img,0,100,500,300);
                    // ctx.fillRect(0,0,600,600);
                }
            }
        }
    </script>
</body>
</html>